import { baseUrlApi, requestClient, type Result } from '#/api/request';

/** 获取列表 */
export const getArticle = (params?: object) => {
  return requestClient.get<Result>(baseUrlApi('/portal/admin/article'), {
    params,
  });
};

/** 获取模型分类列表 */
export const getArticleSelectCategorys = (params?: object) => {
  return requestClient.get<Result>(
    baseUrlApi('/portal/admin/article/select/category'),
    {
      params,
    },
  );
};

/** 获取选择文章列表 */
export const getArticleSelect = (params?: object) => {
  return requestClient.get<Result>(
    baseUrlApi('/portal/admin/article/select/data'),
    {
      params,
    },
  );
};
export const getdownloadtemplate = (params?: object) => {
  return requestClient.get<Result>(
    baseUrlApi('/portal/admin/article/download/template'),
    {
      params,
    },
  );
};



/** 添加 */
export const postArticle = (data?: object) => {
  return requestClient.post<Result>(baseUrlApi('/portal/admin/article'), data);
};
export const exportdata = (data?: object) => {
  return requestClient.post<Result>(baseUrlApi('/portal/admin/article/exportdata'), data);
};
// 正确的接口调用
export const importdata = (data: FormData) => {
  return requestClient.post<Result>(baseUrlApi('/portal/admin/article/importdata'), data, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
};



/** 获取信息 */
export const getArticleInfo = (data: { code: string; id: number }) => {
  const params: { code: string } = { code: data.code };
  return requestClient.get<Result>(
    baseUrlApi(`/portal/admin/article/${data.id}`),
    {
      params,
    },
  );
};

/** 编辑 */
export const putArticle = (data?: any) => {
  return requestClient.put<Result>(
    baseUrlApi(`/portal/admin/article/${data.id}`),
    data,
  );
};

/** 删除 */
export const deleteArticle = (id: number) => {
  return requestClient.delete<Result>(
    baseUrlApi(`/portal/admin/article/${id}`),
  );
};

/** 批量删除 */
export const deleteMultiple = (ids: number[]) => {
  return requestClient.post<Result>(
    baseUrlApi('/portal/admin/article/deleteMultiple'), // 批量删除的路径
    { data: { ids } } // 传递多个 ID
  );
};




/** 设置显示状态 */
export const postArticleStatus = (data?: {
  id?: number;
  ids?: object;
  type: string;
}) => {
  return requestClient.post<Result>(
    baseUrlApi(`/portal/admin/article/status`),
    data,
  );
};

/** 获取列表 */
export const getArticleSelectData = () => {
  return requestClient.get<Result>(
    baseUrlApi('/portal/admin/article/select/data'),
  );
}; 
export const update_sort = (data?: object) => {
  return requestClient.post<Result>(baseUrlApi('/portal/admin/article/update/sort'), data);
};